cmake_minimum_required(VERSION 3.8)
project(final_exam)

# 使用更明确的 C++ 标准
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)

if(CMAKE_COMPILER_IS_GNUCXX OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
  add_compile_options(-Wall -Wextra -Wpedantic)
endif()

# find dependencies
find_package(ament_cmake REQUIRED)
find_package(rclcpp REQUIRED)
find_package(std_msgs REQUIRED)
find_package(geometry_msgs REQUIRED)
find_package(OpenCV REQUIRED) # 提供 OpenCV::OpenCV 或 OpenCV_LIBS

# include path for your headers
# 推荐对 targets 使用 target_include_directories，但保留这个全局也可作为回退
include_directories(${PROJECT_SOURCE_DIR}/include)

if(BUILD_TESTING)
  find_package(ament_lint_auto REQUIRED)
  set(ament_cmake_copyright_FOUND TRUE)
  set(ament_cmake_cpplint_FOUND TRUE)
  ament_lint_auto_find_test_dependencies()
endif()

# 公共实现文件（如果这堆源在多个可执行文件中共享，考虑改为 library）
set(SOURCES
  src/armor_detect.cpp
  src/pose_solver.cpp
  src/kalman_predictor.cpp
)

# 建议把公共代码打包成 library，然后可执行文件只包含各自的 node cpp
add_library(final_exam_core SHARED ${SOURCES})
target_include_directories(final_exam_core PUBLIC
  $<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
  $<INSTALL_INTERFACE:include>
)
# 链接 OpenCV 到这个 library（或直接到单个 exec）
target_link_libraries(final_exam_core ${OpenCV_LIBS})
ament_target_dependencies(final_exam_core rclcpp std_msgs geometry_msgs)

# 每个 node
add_executable(center_node src/center_node.cpp)
target_link_libraries(center_node final_exam_core)
ament_target_dependencies(center_node rclcpp std_msgs geometry_msgs)

add_executable(shoot_node src/shoot_node.cpp)
target_link_libraries(shoot_node final_exam_core)
ament_target_dependencies(shoot_node rclcpp std_msgs geometry_msgs)

add_executable(screen_node src/screen_node.cpp)
target_link_libraries(screen_node final_exam_core)
ament_target_dependencies(screen_node rclcpp std_msgs geometry_msgs)

add_executable(cam_node src/cam_node.cpp)
target_link_libraries(cam_node final_exam_core)
ament_target_dependencies(cam_node rclcpp std_msgs geometry_msgs)

# 安装可执行文件和头文件（必要以便 ros2 run / 安装）
install(TARGETS
  center_node
  shoot_node
  screen_node
  cam_node
  final_exam_core
  ARCHIVE DESTINATION lib
  LIBRARY DESTINATION lib
  RUNTIME DESTINATION lib/${PROJECT_NAME}
)

install(DIRECTORY include/
  DESTINATION include/
)

ament_package()
